package player

import (
	"game_server/logic/center/api"
	"game_server/logic/gate/api"
	"game_server/model"
	"proto/base"
	"proto/player"
	"proto/server/center"
	"proto/server/game"
	"proto/server/gate"
)

type playerRpc struct {
}

var rpc = new(playerRpc)

func (*playerRpc) OnLogin(msg *proto_server_game.OnLogin) {
	center_api.WriteMsg(msg)
}

func (*playerRpc) OnLogout(player *model.Player, reason proto_base.LogoutReason) {
	{
		msg := new(proto_server_center.OnLogout)
		msg.PlayerId = player.Id().String()
		msg.Timestamp = player.LoginTimestamp()
		center_api.WriteMsg(msg)
	}

	{
		msg := new(proto_server_gate.OnLogout)
		msg.PlayerId = player.Id().String()
		msg.Reason = reason

		gateId := player.GateId()
		gate_api.WriteMsg(gateId, msg)
	}
}

func (*playerRpc) SyncData(player *model.Player, msg *proto_player.SyncData) {
	gate_api.SendMsg(player, msg)
}

func (*playerRpc) SyncLevel(player *model.Player, msg *proto_player.SyncLevel) {
	gate_api.SendMsg(player, msg)
}

func (*playerRpc) OnTestSetLevel(player *model.Player, msg *proto_player.OnTestSetLevel) {
	gate_api.SendMsg(player, msg)
}

func (*playerRpc) OnTestSetName(player *model.Player, msg *proto_player.OnTestSetName) {
	gate_api.SendMsg(player, msg)
}
